﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;

using System.Web.UI;
using DotNetNuke;

namespace DotNetNuke.Modules.ActiveForums
{
    public partial class ActiveForums : ForumBase, DotNetNuke.Entities.Modules.IActionable
    {


        #region DNN Actions
        public Entities.Modules.Actions.ModuleActionCollection ModuleActions
        {
            get
            {
                Entities.Modules.Actions.ModuleActionCollection Actions = new Entities.Modules.Actions.ModuleActionCollection();
                Actions.Add(GetNextActionID(), Utilities.GetSharedResource("[RESX:ControlPanel]"), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), false, Security.SecurityAccessLevel.Edit, true, false);
                //Actions.Add(GetNextActionID, Utilities.GetSharedResource("ForumEditor"), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl("ForumEditor"), False, Security.SecurityAccessLevel.Edit, True, False)
                return Actions;
            }
        }
        #endregion

        #region Event Handlers

        protected override void  OnLoad(EventArgs e)
        {
 	         base.OnLoad(e);

            string defaultView = "classic";
            if (Settings["amafDefaultView"] != null)
            {
                if (!(string.IsNullOrEmpty(Settings["amafDefaultView"].ToString())))
                {
                    defaultView = Settings["amafDefaultView"].ToString();
                }
            }
            if (!Page.IsPostBack)
            {
                plhAF.Controls.Clear();
            }

            if (defaultView.ToLowerInvariant() == "advanced")
            {
                Controls.ControlsBase ctl2 = null;
                ctl2 = (Controls.ControlsBase)(LoadControl("~/desktopmodules/activeforums/advanced.ascx"));
                ctl2.ModuleConfiguration = this.ModuleConfiguration;
                plhAF.Controls.Add(ctl2);
            }
            else if (PortalSettings.UserTabId == PortalSettings.ActiveTab.ParentId)
            {
                int userId = -1;
                if (Request.QueryString["UserId"] == null)
                {
                    userId = UserInfo.UserID;
                }
                else
                {
                    userId = Convert.ToInt32(Request.QueryString["UserId"]);
                }
                if (userId == UserInfo.UserID || UserInfo.IsInRole(PortalSettings.AdministratorRoleName))
                {
                    SettingsBase ctl2 = null;
                    ctl2 = (SettingsBase)(LoadControl("~/desktopmodules/activeforums/controls/profile_mypreferences.ascx"));
                    ctl2.ModuleConfiguration = this.ModuleConfiguration;
                    ctl2.LocalResourceFile = "~/desktopmodules/activeforums/app_localresources/sharedresources.resx";
                    plhAF.Controls.Add(ctl2);
                }

            }
            else
            {
                ForumBase ctl = null;
                ctl = (ForumBase)(LoadControl("~/desktopmodules/activeforums/classic.ascx"));
                ctl.ModuleConfiguration = this.ModuleConfiguration;
                plhAF.Controls.Add(ctl);
            }
        }


        #endregion
    }
}